﻿using System;

namespace HoNSharp
{
    class GenericBuffer
    {
        private string _buffer;

        public void InsertNonNTString(string data)
        {
            this._buffer += data;
        }

        public void InsertString(string data)
        {
            this._buffer += data;
            this._buffer += "\0";
        }

        public void InsertDWORD(UInt32 data)
        {
            byte[] tmp = BitConverter.GetBytes(data);
            foreach (byte b in tmp)
            {
                this._buffer += (char)b;
            }
        }

        public void InsertWORD(UInt16 data)
        {
            byte[] tmp = BitConverter.GetBytes(data);
            foreach (byte b in tmp)
            {
                this._buffer += (char)b;
            }
        }

        public void InsertBYTE(byte data)
        {
            this._buffer += Convert.ToChar(data);
        }

        public string GetBuffer()
        {
            return this._buffer;
        }

        public byte[] GetBytes()
        {
            byte[] ret = new byte[this._buffer.Length];
            for (int i = 0; i < this._buffer.Length; i++)
            {
                ret[i] = Convert.ToByte(this._buffer[i]);
            }
            return ret;
        }

        public int GetLength()
        {
            return this._buffer.Length;
        }

        public void Flush()
        {
            this._buffer = "";
        }
    }
}